import Umzug from 'umzug';
import { getMigrations } from './migrations';
import { sequelize } from './sequelize';

export async function getUmzug() {
  const migrations = await getMigrations();
  // console.log(migrations);

  const umzug = new Umzug({
    migrations: Umzug.migrationsList(migrations, [sequelize.getQueryInterface()]),
    // indicates that the migration data should be store in the database
    // itself through sequelize. The default configuration creates a table
    // named `SequelizeMeta`.
    storage: 'sequelize',
    storageOptions: {
      sequelize: sequelize,
      modelName: 'sequelize_meta',
    },
  });
  return umzug;
}
